package UserTable;

import utils.JdbcUtils;

import javax.swing.*;
import utils.JdbcUtils;
import java.util.Map;
import java.util.List;

public class DeleteUser{
    public static void init(){
        JFrame frame=new JFrame();
        List<Map<String, Object>> datas= JdbcUtils.JdbcQuery("User.sql_queryUser");
        if(datas.isEmpty()){
            JOptionPane.showMessageDialog(frame,"没有可删除的管理员");
        }else{
            String[] options=new String[datas.size()];
            int sum=0;
            for(Map<String,Object> map:datas){
                for(String key:map.keySet()){
                    options[sum]=(String)map.get(key);
                    sum++;
                }
            }
            String info=(String)JOptionPane.showInputDialog(frame,"请输入你的选项: ","提示",JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
            if(!info.isEmpty()){
                int yn=JOptionPane.showConfirmDialog(frame,"确定删除吗？","提示",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
                if(yn==JOptionPane.OK_OPTION){
                    JdbcUtils.JdbcUpdate("User.sql_delete_user",info);
                    JOptionPane.showMessageDialog(frame,"删除成功");
                }else{
                    JdbcUtils.JdbcUpdate("Page.sql_delete-user",info);
                    JOptionPane.showMessageDialog(frame,"取消删除");
                }

            }

            }
        }

}